<template>
  <div class="XRadio" @click="handleInput" :style="`width: ${radioWidth}`">
    <div
      :class="{
        radioInput: true,
        active: value + '' === label + '',
      }"
    >
      <p>
        <i></i>
        <span>
          <slot></slot>
        </span>
      </p>
    </div>
  </div>
</template>

<script>
export default {
  name: "XRadio",
  props: {
    value: {
      type: [String, Number],
      required: true,
    },
    label: {
      type: [String, Number],
      required: true,
    },
    width: {
      type: [String, Number],
      default: "100",
    },
  },
  data() {
    return {};
  },
  created() {},
  activated() {},
  computed: {
    radioWidth() {
      let width = parseFloat(this.width);
      return `${width}px`;
    },
  },
  methods: {
    handleInput() {
      this.$emit("input", this.label);
    },
  },
  watch: {
    value(newV, oldV) {
      if (oldV !== newV) {
        this.$emit("change", newV);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
</style>
